<div id="changePwsDialog" class="changePwsDialog">
    <form id="changePwsForm" method="post">
        <div class="form-group">
            <label for="password">新密码</label>
            <input id="password" type="text" class="form-control" name="password" maxlength="30"/>
        </div>
        <div class="form-group text-right dialog-buttons">
            <a class="waves-effect waves-button" href="javascript:;" onclick="changPasswordSubmit();">保存</a>
            <a class="waves-effect waves-button" href="javascript:;" onclick="changePwsDialog.close();">取消</a>
        </div>

    </form>
</div>
<script>


    var id = 0;
    if (location.href.indexOf('#') > 0) {
        id = location.href.split("#")[1];
    }
    function changPasswordSubmit() {
        var data = {};
        $('#changePwsForm').serializeArray().map(function (x) {
            data[x.name] = x.value;
        });
        console.log(data);
        var beforeSend = function () {
            if ($('#password').val() == '') {
                $('#password').focus();
                return false;
            }

        }
        var success = function (result) {
            if (result.status != 'SUCCESS') {
                $.confirm({
                    theme: result.status == 'SUCCESS' ? 'light' : 'dark',
                    animation: 'rotateX',
                    closeAnimation: 'rotateX',
                    title: false,
                    content: result.msg,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'waves-effect waves-button waves-light',
                        }
                    }
                });
            } else {
                changePwsDialog.close();
                $table.bootstrapTable('refresh');
            }
        }
        var error = function (jqXHR, textStatus) {
            $.confirm({
                theme: 'dark',
                animation: 'rotateX',
                closeAnimation: 'rotateX',
                title: false,
                content: textStatus != 'canceled' ? '系统异常' : '请检查密码',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'waves-effect waves-button waves-light'
                    }
                }
            });
        }
        $.ajax({
            type: "PUT",
            url: '/api/user/' + id + '/password',
            data: data,
            beforeSend: beforeSend,
            success: success,
            error: error
        });
    }
</script>